package com.googlecode.npgame.simulation;

/**
 * Represents one frame of the buffer.
 * 
 * @author Josh (joshbruning)
 */
public class Frame {

  private final ElementType packetType;
  private final int maxVolume;

  private int volume;

  public Frame(ElementType packetType, int maxVolume) {
    this.packetType = packetType;
    this.maxVolume = maxVolume;
    // Frames start out empty.
    this.volume = 0;
  }

  public void addPacket(Element packet) {
    if (packet.getElementType() != this.packetType) {
      return;
    }

    this.volume = Math.min(this.maxVolume, this.volume + packet.getVolume());
  }

  public ElementType getPacketType() {
    return this.packetType;
  }

  public int getMaxVolume() {
    return this.maxVolume;
  }

  public int getVolume() {
    return this.volume;
  }

  public boolean isFull() {
    return this.volume == this.maxVolume;
  }
}
